/**
 * Created by sxx on 2017/5/6.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";

jQuery(function () {
    App.init();
    
    let token = sessionStorage.getItem('supplier_token');
    function getArgs(){
        var args = {};
        var match = null;
        var search = decodeURIComponent(location.search.substring(1));
        var reg = /(?:([^&]+)=([^&]+))/g;
        while((match = reg.exec(search))!==null){
            args[match[1]] = match[2];
        }
        return args;
    }
    var projId = getArgs().id;

    $('.J_return').click(function(){
        window.history.back();
    });

    jQuery.ajax({
        url: HOST_ADDR+'/cpmp/bidProjOffMngForSplr/viewProjDtl/'+projId,
        type: 'get',
        // data: JSON.stringify(data),
        dataType: 'json',
        contentType:"application/json",
        headers: {
            'access_token': token,
            'login_type': 'splr'
        },
        success: function(resp){
            if (!resp.success) {
                console.log(resp.msgCod+' '+resp.msgInf);
                return;
            }
            var projqotCntTyp = '非实时报价';
            var bidRngTyp = '非定向招标';
            var bidOpenTim = '',bidEndTim = '',projMemo = '',splrNames = '';
            if (resp.data.bidProjOff.qotCntTyp == 2) {
                projqotCntTyp='实时报价';
            }
            if (resp.data.bidProjOff.bidRngTyp == 1) {
                bidRngTyp='定向招标';
            }
            if (resp.data.bidProjOff.bidOpenTim != null&&resp.data.bidProjOff.bidOpenTim !='') {
                bidOpenTim = (new Date(resp.data.bidProjOff.bidOpenTim)).Format("yyyy-MM-dd hh:mm:ss");
            }
            if (resp.data.bidProjOff.bidEndTim != 'null'&&resp.data.bidProjOff.bidEndTim !='') {
                bidEndTim = (new Date(resp.data.bidProjOff.bidEndTim)).Format("yyyy-MM-dd hh:mm:ss");
            }
            if (resp.data.bidProjOff.projMemo != null&&resp.data.bidProjOff.projMemo !='') {
                projMemo = resp.data.bidProjOff.projMemo;
            }
            if(resp.data.splrs){
                $.each(resp.data.splrs,function(index,item){
                    splrNames += item.splrNam + " ";
                })
            }
            var matTyp = resp.data.bidProjOff.matTyp;
            if(resp.data.matTypDesc!=null && resp.data.matTypDesc!=''){
                matTyp = resp.data.matTypDesc;
            }
            jQuery('.basicInfo').append('<div class="portlet-body"><table class="table table-striped table-bordered"><tbody><tr>' +
                '<td width="16%">项目名称：</td><td colspan="2">'+resp.data.bidProjOff.projNam+'</td> ' +
                '<td width="16%">项目编号：</td> <td colspan="2">'+resp.data.bidProjOff.projNbr+'</td></tr> <tr><tr>' +
                '<td width="16%">物料品类：</td><td colspan="2">'+matTyp+'</td>' +
                '<td width="16%">招标单位：</td><td colspan="2">'+resp.data.bidProjOff.bidDpt+'</td></tr> <tr>' +
                '<td width="16%">招标单位地址：</td><td colspan="2">'+resp.data.bidProjOff.bidDptAddr+'</td>' +
                '<td width="16%">投标保证金（元）：</td><td colspan="2">'+resp.data.bidProjOff.bidDpst+'</td></tr><tr>' +
                '<td width="16%">联系人：</td><td colspan="2">'+resp.data.bidProjOff.ctct+'</td>' +
                '<td width="16%">联系电话：</td><td colspan="2">'+resp.data.bidProjOff.ctctTel+'</td></tr><tr>' +
                '<td width="16%">投标开标时间：</td><td colspan="2">'+bidOpenTim+'</td>' +
                '<td width="16%">投标截止时间：</td><td colspan="2">'+bidEndTim+'</td></tr><tr>' +
                '<td>招标范围类型：</td><td colspan="2">'+bidRngTyp+'</td>' +
                '<td width="16%">指定招标供应商：</td><td colspan="2">'+splrNames+'</td></tr></tr><tr>' +
                '<td>备注信息：</td><td colspan="5">'+projMemo+'</td></tr><tr>' +
                '<td>招标书内容:</td><td colspan="5" rowspan="3">' + resp.data.bidProjOff.bidBok + '</td></tr></tbody></table></div>');

            var atches = resp.data.atches;
            if ((atches!=null && atches!='undefined') && atches.length > 0){
                for (var i= 0;i<atches.length;i++) {
                    jQuery('#tab_3').append('<div class="controls atchDiv"><span src="'+atches[i].atchUrl+'">'+atches[i].atchNam+'</span>' +
                        '&emsp;<a target="_blank" href="'+HOST_FILE+atches[i].atchUrl+'">查看</a></div>');
                }
            }
        },
        error:function(err){
            console.log(err);
        }
    });
});
